<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      >

    <h:head>
        <title>Ajax com JSF 2.0</title>
        <style type="text/css">
            *{
                font-size: 12px !important;
            }
            #bt1{
            }
            #bt2{
                position: relative;
                top: -31px;
                left: 65px;
                /*top: 158px;
                left: 90px;*/
            }
        </style>
    </h:head>

    <p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>  

    <p:dialog modal="true" widgetVar="statusDialog" header="Status"  
              draggable="false" closable="false">  

    </p:dialog>

    <h:body onload="#{loginBean.validaUsuarioSessaoPaginas}">
        <p:panel id="painel" header="Cadastro de Doutor">
            <h:form id="form" >  
                <p:messages id="mensagens" />

                <h:panelGrid columns="2">  
                    <h:outputText value="Nome" />  
                    <p:inputText id="nome" label="Nome" value="#{doutorBean.nome}" disabled="#{doutorBean.camposDesativados}"/>

                    <h:outputText value="Horário Inicial" />
                    <p:calendar label="Horário Inicial" value="#{doutorBean.horarioTrabInicial}" id="horarioinicial"  required="true" disabled="#{doutorBean.camposDesativados}" pattern="HH:mm" timeOnly="true" />  

                    <h:outputText value="Horário Final" />
                    <p:calendar label="Horário Final" value="#{doutorBean.horarioTrabFinal}" id="horariofinal" required="true" disabled="#{doutorBean.camposDesativados}" pattern="HH:mm" timeOnly="true" />  

                    <h:outputText value="CRO" />  
                    <p:inputText label="CRO" id="cro" value="#{doutorBean.cro}" required="true" disabled="#{doutorBean.camposDesativados}"/>

                </h:panelGrid>  
                <div id="bt1">
                    <p:commandButton id="btSalvar" value="Salvar" update="form, :formBotoes, :formPesquisa" actionListener="#{doutorBean.salvar}" disabled="#{doutorBean.salvarDesativado}"/>
                </div>
            </h:form>
            <div id="bt2">
                <h:form id="formBotoes">
                    <p:commandButton id="btNovo" update=":form, formBotoes" value="Novo" actionListener="#{doutorBean.novo}" disabled="#{doutorBean.novoDesativado}"/>  
                    <p:commandButton id="btEditar" update=":form, formBotoes" value="Editar" actionListener="#{doutorBean.editar}" disabled="#{doutorBean.editarDesativado}"/> 
                    <p:commandButton id="btExcluir" update=":form, formBotoes, :formPesquisa" value="Excluir" actionListener="#{doutorBean.excluir}" disabled="#{doutorBean.excluirDesativado}"/> 
                    <p:commandButton id="btCancelar" update=":form, formBotoes" value="Cancelar" actionListener="#{doutorBean.cancelar}" disabled="#{doutorBean.cancelarDesativado}"/>
                    <p:commandButton id="btPesquisar" update=":form, formBotoes, :formPesquisa" value="Pesquisar"  disabled="#{doutorBean.pesquisarDesativado}" onclick="doutorDialog.show()" type="button" />
                    <p:commandButton id="btRelatório" value="Relatório"  actionListener="#{doutorBean.relatorio}" disabled="#{doutorBean.novoDesativado}"/>
                </h:form>
            </div>
        </p:panel>

        <p:dialog id="dialog" header="Doutores" widgetVar="doutorDialog" resizable="false"  
                  width="800" height="500" showEffect="clip" hideEffect="fold"> 

            <h:form id="formPesquisa"> 
            <h:outputLabel for="codigoDoutor" value="Nome: *" /> 
            <p:inputText id="codigoDoutor" value="#{doutorBean.nomeDoutor}" /> 
              <p:commandButton id="btPesquisarDoutorPorNome" value="Pesquisar" update="formPesquisa"  />
                <p:dataTable id="doutores" var="doutor" value="#{doutorBean.filtraDoutorNome}" rowKey="#{doutor.idDoutor}"  
                             widgetVar="teste"     selection="#{doutorBean.doutorSelecionado}" selectionMode="single" emptyMessage="Nenhum doutor encontrado">  

                    <f:facet name="header">  
                        Selecione algum doutor para edição ou exclusão  
                    </f:facet>  

                    <p:column headerText="Doutor" width="300">  
                        #{doutor.nome}  
                    </p:column>  

                    <p:column headerText="CRO" width="100">  
                        #{doutor.cro}  
                    </p:column>  

                    <p:column headerText="H. Inicial" width="40">  
                        #{doutor.horaInicialFormatada}  
                    </p:column>  

                    <p:column headerText="H. Final" width="40">  
                        #{doutor.horaFinalFormatada} 
                    </p:column>  

                    <f:facet name="footer">  
                        <p:commandButton id="viewButton" value="OK" icon="ui-icon-search"  update=":form, :formBotoes" onclick="doutorDialog.hide()" />  
                    </f:facet>  

                </p:dataTable> 

            </h:form>
        </p:dialog> 

    </h:body>

</html>
